#!/bin/sh

source /script/directory
lxphp.exe ../bin/fix/fix-qmail-assign.php $*

exit

d="/home/lxadmin/mail/domains"
q="/var/qmail"

echo "Fix Qmail User Assign"

'rm' -f ${q}/users/assign ${q}/control/rcpthosts ${q}/control/virtualdomains

cd ${d}
 
for i in * ; do
	if [ ! -d ${i} ] ; then
		continue
	fi

	if [ ! -f ${i}/.qmail-default ] ; then
		echo "| /home/vpopmail/bin/vdelivermail '' bounce-no-mailbox" > ${i}/.qmail-default
	fi

	u=$(ls -l ${i}/.qmail-default|awk '{print $3}')
	uid=$(id -u ${u})
	g=$(ls -l ${i}/.qmail-default|awk '{print $4}')
	gid=$(id -g ${g})

	echo "+${i}-:${i}:${uid}:${gid}:${d}${i}:-::" >> ${q}/users/assign
	echo "${i}:${i}" >> ${q}/control/virtualdomains
	echo "${i}" >> ${q}/control/rcpthosts

	echo "- for '${i}' under '${u}'"
done

if [ $# -eq 0 ] ; then
	echo "." >> ${q}/users/assign
fi

/var/qmail/bin/qmail-newu